const app = getApp();
const common = require('../../utils/common.js');
const api = require('../../config/api.js');

Page({
  data: {
    imgUrl: app.globalData.imgurl
  },
  onLoad: function (options) {

  },
  onShow: function () {

  },
  rejectInfo: function () {
    wx.navigateBack({
      delta: 1
    })
  },
  bindGetUserInfo: function (e) {
    var that = this;
    if (e.detail.errMsg != "getUserInfo:ok") {
      return;
    }
    var r = e.detail;
    var data = {
      rawData: r.rawData,
      signature: r.signature,
      encryptedData: r.encryptedData,
      iv: r.iv,
      nickName: r.userInfo.nickName,
      gender: r.userInfo.gender,
      avatarUrl: r.userInfo.avatarUrl,
      gender: r.userInfo.gender,
      sessionKeyToken: wx.getStorageSync("sessionKeyToken")
    };
    wx.showLoading({
      title: '登录中'
    })
    wx.request({
      url: api.GetUserInfoUrl,
      data: data,
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        wx.hideLoading();
        if (res.data.type == 'success') {
          wx.setStorageSync("token", res.data.data.token);
          wx.setStorageSync("memberId", res.data.data.memberId);
          common.showSuccessToast(res.data.content);
          setTimeout(function () {
            wx.navigateBack({
              delta: 1
            })
          }, 1500);
        } else {
          common.showErrorToast(res.data.content);
        }
      }, complete: function (e) {
        if (e.statusCode != 200) {
          wx.showToast({ title: "请求失败", icon: 'none', duration: 2000 });
          wx.hideLoading();
        }
      }
    });
  }
})